define(['jquery','api','user','util'],function($,api,user,util){
	var vm, 
		startid,
	   controller = {
	   init:function(){
		   api.setTitle(L('html_title_notice'));
	   	   api.footerShow(1);//显示底部导航
		   api.initFooter('notice');
		   api.headerShow(0);
		   
		   this.render();
	   },
	   render:function(){
	   	   var that=this;
	   	   $('#common').html('<div id="notices"></div>');

	       require(['text!pages/notice/index.html','Vue'],function(tpl,Vue){
	            vm=new Vue({
	               el:'#notices',
	               data:{
	               	noRecord:'/static/img/none_content.png',
	               	  show:true,
	               	  loading:false,
	               	  noMore:false,
	               	  showMore:false,
	               	  notices:[]
	               },
	               filters:{
		              	contentFormat:function(s){
		              		var str=s.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"");
		              	    return util.subString(str,70,1);
		              	},
		              	titleFormat:function(v){
		              	     return util.subString(v,35,1);
		              	}
		           },
	               methods:{
		               	more:function(){
		               		that.loadNotices(1);
		               	}
	               },
	               template:tpl
	            });
	            
	            that.loadNotices();
	       });
	       
	   },
	   loadNotices:function(more){
	   		if(more === undefined){
                this.notices=[];
                startid=0;
            }
	   		
	   		var temp,
	   			pageSize=20;
	   		vm.loading=true;
//	   	   	vm.notices=[{id:'1',title:'关于xxx公告',date:'2017-01-03'}];

			if(user.isLogin()){
				api.noticesLogin(
			   	   	{id:startid,count:pageSize},
			   	   	function(rs){
				   	   	vm.loading=false;
			   	       if(rs.retcode==0 && rs.data){
			   	       		vm.noMore=false;
			   	           	temp=rs.data;
		                    vm.notices=vm.notices.length?vm.notices.concat(temp):temp;
		                    var len = temp.length;
		                    startid+=len;
		                    if(len>=pageSize){
		                       vm.showMore=true;
		                    }else{
		                       vm.showMore=false;
		                    }
			   	       }else{
			   	       		vm.noMore=true;
			   	       }
			   	   },
			   	   function(){//err
			   	   		vm.loading=false;
			   	   }
		   	   );
			}else{
		   	   api.notices(
			   	   	{id:startid,count:pageSize},
			   	   	function(rs){
				   	   	vm.loading=false;
			   	       if(rs.retcode==0 && rs.data){
			   	       		vm.noMore=false;
			   	           	temp=rs.data;
		                    vm.notices=vm.notices.length?vm.notices.concat(temp):temp;
		                    var len = temp.length;
		                    startid+=len;
		                    if(len>=pageSize){
		                       vm.showMore=true;
		                    }else{
		                       vm.showMore=false;
		                    }
			   	       }else{
			   	       		vm.noMore=true;
			   	       }
			   	   },
			   	   function(){//err
			   	   		vm.loading=false;
			   	   }
		   	   );
			}
	   },
	   onRouteChange:function(){
	       if(vm)vm.show=false;
	   }
	}
    return controller;
})